//
//  CZTabbar.swift
//  CZWeiBo1
//
//  Created by 1 on 15/11/22.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class CZTabbar: UITabBar {

    
    override func layoutSubviews() {
        let width=bounds.size.width/5
        //创建frame
        let frame=CGRect(x: 0, y: 0, width: width, height: bounds.size.height)
        var index=0
        for view in self.subviews{
            if view is UIControl && !(view is UIButton){//只有系统的tabbarButton才设置他的frame
                
                view.frame=CGRectOffset(frame, CGFloat(index)*width, 0)
                
                index++
                if index==2{
                    index++
                }
            }
            
            
        }
        
        //设置发表按钮的frame
        composeButton.frame=CGRectOffset(frame, 2*width, 0)
        
    }
    
    lazy var composeButton:UIButton={
        let button=UIButton()
        //设置按钮的一些属性
        button.setBackgroundImage(UIImage(named:"tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        //设置按钮的图片
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        //添加到tabbar中
        self.addSubview(button)
        
        
        return button
        }()
    
}
